<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const obj = {
            arr: [
                {
                    a: 'b',
                    c: 'd'
                },
                {
                    e: 'f'
                }
            ],
            item: {
                name : 'cui',
                age: 19
            }
        }
        const isObject = val => Object.prototype.toString.call(val) === '[object Object]';
        const isArray = val => Object.prototype.toString.call(val) === '[object Array]';
        function deepClone(target) {
            let root = {};
            const loopTree = [
                {
                    parent: root,
                    data: target,
                    key: undefined,
                    isArray: isArray(target)
                }
            ];
            while(loopTree.length) {
                let node = loopTree.pop();
                let parent = node.parent;
                let key = node.key;
                let data = node.data;
                let res = parent;
                if(key !== undefined) {
                    res = parent[key] = node.isArray ? [] : {};
                }
                for(let k in data) {
                    if (data.hasOwnProperty(k)) {
                        if (typeof data[k] === 'object') {
                            // 下一次循环
                            loopTree.push({
                                parent: res,
                                key: k,
                                data: data[k],
                                isArray: isArray(data[k])
                            });
                        } else {
                            res[k] = data[k];
                        }
                    }
                }
            }


            return root;
        }

        console.log(deepClone(obj))

    </script>
</body>
</html>